package com.ruoyi.web.operate.stock.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.operate.stock.domain.Stock;
import com.ruoyi.web.operate.stock.service.IStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人才股票Controller
 *
 * @author liuyu
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/operate/stock")
public class StockController extends BaseController {
    @Autowired
    private IStockService stockService;

    /**
     * 查询人才股票列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Stock stock) {
        startPage();
        List<Stock> list = stockService.selectStockList(stock);
        return getDataTable(list);
    }

    /**
     * 查询正在发行人才股票列表
     */
    @GetMapping("/listOngoStock")
    public TableDataInfo listOngoStock(Stock stock) {
        startPage();
        List<Stock> list = stockService.selectOngoPublishStock(stock);
        return getDataTable(list);
    }

    /**
     * 根据购买人ID查询持有人的对应股票
     *
     * @return 股票集合
     */
    @GetMapping("/selectHoldStockList")
    public TableDataInfo selectHoldStockList() {
        startPage();
        List<Stock> list = stockService.selectHoldStockList();
        return getDataTable(list);
    }

    /**
     * 查询完成发行人才股票列表
     */
    @GetMapping("/listFinishStock")
    public TableDataInfo listFinishStock(Stock stock) {
        startPage();
        List<Stock> list = stockService.selectFinishPublishStock(stock);
        return getDataTable(list);
    }

    /**
     * 根据发行人id查股票信息
     * @return
     */
    @GetMapping("/selectUpdateStockList")
    public TableDataInfo selectUpdateStockList() {
        startPage();
        List<Stock> list = stockService.selectUpdateStockList();
        return  getDataTable(list);
    }

    /**
     * 导出人才股票列表
     */
    @Log(title = "人才股票", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Stock stock) {
        List<Stock> list = stockService.selectStockList(stock);
        ExcelUtil<Stock> util = new ExcelUtil<Stock>(Stock.class);
        return util.exportExcel(list, "人才股票数据");
    }

    /**
     * 获取人才股票详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(stockService.selectStockById(id));
    }

    /**
     * 获取人才股票详细信息
     */
    @GetMapping(value = "getStockByOwner/{id}")
    public AjaxResult getStockByOwner(@PathVariable("id") Long id) {
        return AjaxResult.success(stockService.selectStockById(id));
    }

    /**
     * 新增人才股票
     */
    @Log(title = "人才股票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Stock stock) {
        return toAjax(stockService.insertStock(stock));
    }

    /**
     * 修改人才股票
     */
    @Log(title = "人才股票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stock stock) {
        return toAjax(stockService.updateStock(stock));
    }

    /**
     * 删除人才股票
     */
    @Log(title = "人才股票", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockService.deleteStockByIds(ids));
    }
}
